package com.tedu.brand.service.impl;

import com.tedu.brand.dao.BrandDao;
import com.tedu.brand.pojo.Brand;
import com.tedu.brand.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j // 系统底层会生成:private static final Logger log = LoggerFactory.getLogger(BrandServiceImpl.class);
@Service
public class BrandServiceImpl implements BrandService {
    //private static final Logger log = LoggerFactory.getLogger(BrandServiceImpl.class);

    @Autowired
    private BrandDao brandDao;

    @Override
    public List<Brand> findBrands(String name) {
        long begin = System.currentTimeMillis();
        log.info("begin:{}", begin);
        List<Brand> list = brandDao.findBrands(name);
        long end = System.currentTimeMillis();
        log.info("end:{}", end);
        log.info("total:{}", end - begin);
        return list;
    }

    @Override
    public Brand findById(Long id) {
        long begin = System.currentTimeMillis();
        log.info("begin:{}", begin);
        Brand brand = brandDao.findById(id);
        long end = System.currentTimeMillis();
        log.info("end:{}", end);
        log.info("total:{}", end - begin);
        return brand;
    }

    @Override
    public int insertBrand(Brand brand) {
        long begin = System.currentTimeMillis();
        log.info("begin:{}", begin);
        int rows = brandDao.insertBrand(brand);
        long end = System.currentTimeMillis();
        log.info("end:{}", end);
        log.info("total:{}", end - begin);
        return rows;
    }

    @Override
    public int updateBrand(Brand brand) {
        long begin = System.currentTimeMillis();
        log.info("begin:{}", begin);
        int rows = brandDao.updateBrand(brand);
        long end = System.currentTimeMillis();
        log.info("end:{}", end);
        log.info("total:{}", end - begin);
        return rows;
    }

    @Override
    public int deleteBrand(Long id) {
        long begin = System.currentTimeMillis();
        log.info("begin:{}", begin);
        int rows = brandDao.deleteBrand(id);
        long end = System.currentTimeMillis();
        log.info("end:{}", end);
        log.info("total:{}", end - begin);
        return rows;
    }
}
